<?php 
App::import('Vendor','xtcpdf');  
$pdf = new XTCPDF();

$textfont = 'freesans'; 
$pdf->SetAuthor("SIGEM"); 
$pdf->SetAutoPageBreak( false ); 
$pdf->setHeaderFont(array($textfont,'',40));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

// add a page (required with recent versions of tcpdf) 
$pdf->AddPage(); 

// Now you position and print your page content 
// example:  
$pdf->SetTextColor(0, 0, 0); 
$pdf->SetFont($textfont,'B', 15);
$pdf->Ln(15);
$pdf->Cell(0, 12, 'CAUTELA', 0,1,'C'); 
$pdf->Ln(10);

$tbl = "";
foreach ($emprestimo['Itensemprestimo'] as $item) {
	$tbl .="<tr>";
	$tbl .="<td>{$item['id']}</td>";
	$tbl .="<td>{$item['Equipamento']['descricao']}</td>";
	$tbl .="<td>{$item['quantidade']}</td>";
	$tbl .="</tr>";
}

$created = date('d/m/Y', strtotime($emprestimo["Emprestimo"]["created"])) ;
$html = '
	<p>Em ' . $created . ', eu <strong>' . $emprestimo["Aluno"]["nome"] . '</strong>, RG nº ' . $emprestimo["Aluno"]["rg"] . ', estou responsável pelos equipamento(s) abaixo:</p>
	<p style="text-align:center;">
		<table cellspacing="0" cellpadding="1" border="1">
			<tr>
				<th>Código</th>
				<th>Equipamento</th>
				<th>Quantidade</th>
			</tr>'
			. $tbl . '  
		</table>
	</p>
';

$pdf->SetFont($textfont,'', 12);
$pdf->writeHTML($html, true, false, true, false, '');

$pdf->Ln(15);
$pdf->SetFont($textfont,'B', 14);
$pdf->Cell(0, 12, 'RENOVAÇÕES', 0,1,'C');
$pdf->Ln(3);

$html = '<p>Os equipamentos, acima descriminados, foram renovados nas seguintes datas:</p>';
$pdf->SetFont($textfont,'', 12);
$pdf->writeHTML($html, true, false, true, false, '');

$pdf->Ln(2);
$pdf->Cell(40, 5, 'Data', 0, 0,'C');
$pdf->Cell(80, 5, 'Assinatura', 0, 1,'C');
for ($i = 0; $i < 5; $i++) {
	$pdf->Cell(40,4,'____/____/_____', 0, 0,'C');
	$pdf->Cell(80,4,'___________________________', 0, 1,'C');
	$pdf->Ln(1);
}

echo $pdf->Output('cautela.pdf', 'I'); 
?>